<script lang="ts" setup>
import { ref, defineEmits, computed } from 'vue'
/* 后面按钮、文字 */
// 入参

interface Props {
  type?: string
  loading?: boolean
  formItem?: object
  disabled?: boolean
}
const props = withDefaults(defineProps<Props>(), {
  formItem: Object,
  disabled: false,
  loading: false,
})
const emit = defineEmits(['exportCallBack', 'update:loading'])
const item = ref<any>(props.formItem)
const type = ref<any>(props.type)
const text = computed(() => {
  return props.type === 'prev' ? item.value.prevText : item.value.suffixText
})
const loadingValue = computed({
  get() {
    return props.loading
  },
  set(val) {
    emit('update:loading', val)
  },
})
/**
 * 按钮操作
 */
const suffixBtnClick = () => {
  // 抛出事件
  emit(
    'exportCallBack',
    props.type,
    props.type === 'prev' ? item.value.prevFunctionName : item.value.suffixFunctionName,
  )
}
</script>
<template>
  <div
    class="suffix-item"
    :class="{ 'right-margin': type === 'prev', 'left-margin': type === 'suffix' }"
  >
    <!-- 按钮 -->
    <el-button
      v-if="item.suffixType === 'button'"
      :disabled="disabled"
      :loading="loadingValue"
      @click="suffixBtnClick"
      plain
      color="#7f98b1"
      >{{ text }}</el-button
    >
    <span v-else-if="item.suffixType === 'text'" class="text">{{ text }}</span>
  </div>
</template>
<style lang="scss" scoped>
.suffix-item {
  margin-left: 10px;
  line-height: 24px;
}
.right-margin {
  margin-right: 10px;
}
.left-margin {
  margin-left: 10px;
}
.text {
  display: inline-block;
}
.ep-button {
  min-width: 48px;
}
</style>
